{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2d000c6f-b435-4224-9fca-2a46492648e0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您好！我是由中国的深度求索（DeepSeek）公司开发的智能助手DeepSeek-R1。如您有任何任何问题，我会尽我所能为您提供帮助。\n"
     ]
    }
   ],
   "source": [
    "import dashscope\n",
    "from dashscope.api_entities.dashscope_response import Role\n",
    "dashscope.api_key = \"sk-882e296067b744289acf27e6e20f3ec0\"\n",
    "\n",
    "# 封装模型响应函数\n",
    "def get_response(messages):\n",
    "    response = dashscope.Generation.call(\n",
    "        model='deepseek-r1',  # 使用 deepseek-r1 模型\n",
    "        messages=messages,\n",
    "        result_format='message'  # 将输出设置为message形式\n",
    "    )\n",
    "    return response\n",
    "\n",
    "# 测试对话\n",
    "messages = [\n",
    "    {\"role\": \"system\", \"content\": \"You are a helpful assistant\"},\n",
    "    {\"role\": \"user\", \"content\": \"你好，你是什么大模型？\"}\n",
    "]\n",
    "response = get_response(messages)\n",
    "print(response.output.choices[0].message.content)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
